package com.situ.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mall.mapper.AdminMapper;
import com.situ.mall.pojo.Admin;
import com.situ.mall.pojo.query.AdminQuery;
import com.situ.mall.service.IAdminService;
import com.situ.mall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements IAdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin login(String username, String password) {
        return adminMapper.login(username,password);
    }

    @Override
    public PageResult<Admin> list(AdminQuery adminQuery) {
        PageHelper.startPage(adminQuery.getPage(),adminQuery.getLimit());
        List<Admin> list = adminMapper.list(adminQuery);
        PageInfo pageInfo = new PageInfo(list);
        int count = (int)pageInfo.getTotal();
        return new PageResult<>(0,"",count,list);
    }

    @Override
    public void deleteById(Integer id) {
        adminMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        adminMapper.deleteAll(ids);
    }

    @Override
    public void add(Admin admin) {
        adminMapper.insertSelective(admin);
    }
}
